package com.fp.m7.client.view;

import com.fp.m7.client.MyMessages;
import com.fp.m7.client.presenter.NewCommentPresenter;
import com.fp.m7.client.widget.InfoPopup;
import com.fp.m7.client.widget.NewCommentWidget;
import com.fp.m7.shared.ValidationResult;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * NewCommentWidget enriched with some validation methods.
 * 
 * @author 7
 */
public class NewCommentView extends Composite implements NewCommentPresenter.Display {

    private static MyMessages msg = GWT.create(MyMessages.class);
    
    private NewCommentWidget newCommentWidget;

    public NewCommentView() {
        Panel panel = new VerticalPanel();
        panel.addStyleName("centered");
        initWidget(panel);

        panel.add(new Label(msg.newCommentDescription()));

        panel.add(newCommentWidget = new NewCommentWidget());
    }

    @Override
    public void showErrors(ValidationResult result) {
        if (!result.isOk()) {
            InfoPopup.showPopup(newCommentWidget.getContents(), msg.newCommentRegexFail());
        }
    }

    @Override
    public HasText getContents() {
        return newCommentWidget.getContents();
    }

    @Override
    public void setContents(String avatarUrl) {
        newCommentWidget.setContents(avatarUrl);
    }

    @Override
    public HasClickHandlers getProfileButton() {
        return newCommentWidget.getProfileButton();
    }

    @Override
    public HasClickHandlers getSubmitButton() {
        return newCommentWidget.getSubmitButton();
    }

    @Override
    public void clear() {
        newCommentWidget.clear();
    }

}
